package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.InformationType;
import me.xue.communityhealth.repo.InformationTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationTypeService implements BaseService<InformationType, Integer> {

    private final InformationTypeRepository repository;

    @Autowired
    public InformationTypeService(InformationTypeRepository repository) {
        this.repository = repository;
    }

    @Override
    public int save(InformationType informationType) {
        return repository.save(informationType);
    }

    @Override
    public int update(InformationType informationType) {
        return repository.update(informationType);
    }

    @Override
    public int delete(Integer which) {
        return repository.delete(which);
    }

    public InformationType findOne(Integer id) {
        InformationType informationType = repository.findOne(id);
        if (informationType == null) {
            throw new ObjectNotFoundException();
        }
        return informationType;
    }

    @Override
    public List<InformationType> findAll() {
        return repository.findAll();
    }
}
